<?php

header( 'Location: http://www.uuch.com/tools/freight/index/' ) ;
class ToolController extends Uuch_BaseController{
    
    public function expressAction(){
        $cid = $this->getSafeParam("cid");
		if (!$cid) {
			$cid = $this->getSafeParam("country_id");	
		}
        $this->appendCss('/css/share.css')->appendCss('/css/tool.css')->appendScript('/js/jquery.min.js');
        $this->setTitle('国际运费估算 | 常用工具');        
        if($cid){
            $city = Application_Model_city::load($cid);
            $this->view->city = $city;
        }else{
            $city = Uuch_Util::getCurrentCity();
            $this->view->city = $city;
        }
        $words = array();
        for($i=0;$i<26;$i++){
            $words[]= chr(65+$i);
        }
        $this->view->words = $words;
        
        $prices = Application_Model_ExpressPrice::getPricesByCity($city->Id);
         foreach ($prices as $item){
            $item->SortKey = $item->Express->OrderBy;
        }
        
        $this->view->prices = Uuch_Util::quickSort($prices, 'firstPrice');
    }
	
	public function expressnewAction() {
		$cid = $this->getSafeParam("cid");
        $this->appendCss('/css/share.css')->appendCss('/css/tool.css')->appendScript('/js/jquery.min.js');
        $this->setTitle('国际运费估算 | 常用工具');        
        if($cid){
            $city = Application_Model_city::load($cid);
            $this->view->city = $city;
        }else{
            $city = Uuch_Util::getCurrentCity();
            $this->view->city = $city;
        }
        $words = array();
        for($i=0;$i<26;$i++){
            $words[]= chr(65+$i);
        }
        $this->view->words = $words;
        
        $prices = Application_Model_ExpressPrice::getPricesByCity($city->Id);
         foreach ($prices as $item){
            $item->SortKey = $item->Express->OrderBy;
        }
        
        $this->view->prices = Uuch_Util::quickSort($prices, 'firstPrice');
		$this->_helper->layout()->setLayout('empty');	
	}
    
    public function visitingAction()
    {
        $this->appendCss('/css/share.css')->appendCss('/css/tool.css')->appendScript('/js/jquery.min.js');
        $this->setTitle('国内运费估算 | 常用工具'); 
        $cityItem = Application_Model_city::GetByParentId(Application_Model_city::ParentDefaultCity, null);
        $townItem = Application_Model_city::GetByParentId(Application_Model_city::ParentDefaultTown, null);
        $prices = Application_Model_ExpressPrice::getPricesByCity($townItem[0]["id"]);
         foreach ($prices as $item){
            $item->SortKey = $item->Express->OrderBy;
        }
        $city = Uuch_Util::getCurrentCity();
        $this->view->city = $city;
        $words = array();
        for($i=0;$i<26;$i++){
            $words[]= chr(65+$i);
        }
        $this->view->words = $words;
        $this->view->prices = Uuch_Util::quickSort($prices, 'SortKey');
        $this->view->cityAll = $cityItem;
        $this->view->townAll = $townItem;
    }
	
	public function visitingnewAction()
    {
        $this->appendCss('/css/share.css')->appendCss('/css/tool.css')->appendScript('/js/jquery.min.js');
        $this->setTitle('国内运费估算 | 常用工具'); 
        $cityItem = Application_Model_city::GetByParentId(Application_Model_city::ParentDefaultCity, null);
        $townItem = Application_Model_city::GetByParentId(Application_Model_city::ParentDefaultTown, null);
        $prices = Application_Model_ExpressPrice::getPricesByCity($townItem[0]["id"]);
         foreach ($prices as $item){
            $item->SortKey = $item->Express->OrderBy;
        }
        $city = Uuch_Util::getCurrentCity();
        $this->view->city = $city;
        $words = array();
        for($i=0;$i<26;$i++){
            $words[]= chr(65+$i);
        }
        $this->view->words = $words;
        $this->view->prices = Uuch_Util::quickSort($prices, 'SortKey');
        $this->view->cityAll = $cityItem;
        $this->view->townAll = $townItem;
		$this->_helper->layout()->setLayout('empty');	
    }
    
    public function visitingcultAction()
    {
        $weight = $this->getSafeParam('weight');
        $cityId = $this->getSafeParam('cityId');
        $townId = $this->getSafeParam("townId");
        $length = $this->getSafeParam('length');
        $width = $this->getSafeParam('width');
        $height = $this->getSafeParam('height');
        $isWay = $this->getSafeParam("isWay");
        $cId = $this->getSafeParam("cId");
        $packWeight = Uuch_Util::getPackage($weight*1000);
        $volumeWeight = $weight;
        if($length && $width && $height)
        {
            $volumeWeight = ($length * $width * $height) / 6000;
            if($volumeWeight<$weight)
                $volumeWeight = $weight;
        }
        $city = Application_Model_city::load($cId);
        $cityItem = Application_Model_city::load($cityId);
        $townItem = Application_Model_city::load($townId);
        $this->view->length = $length;
        $this->view->width = $width;
        $this->view->height = $height;
        $this->view->weight =$weight;
        $this->view->volumeWeight = $volumeWeight;
        $this->view->city = $city;
        $this->view->cityName = $cityItem->name;
        $this->view->townName = $townItem->name;
        $this->view->isWay = $isWay;
        $this->view->packWeight = $packWeight;
        $this->view->prices = Application_Model_ExpressPrice::getPricesByCity($townId);
        $this->view->WayPrices = Application_Model_ExpressPrice::getPricesByCity($cId);
        $this->disableLayout();
    }

    public function visitingdetailAction()
    {
        $cityId = $this->getSafeParam("cityId");
        $townId = $this->getSafeParam("townId");
        $isWay = $this->getSafeParam("isWay");
        $cId = $this->getSafeParam("cId");
        $city = Application_Model_city::load($cId);
        $cityItem = Application_Model_city::load($cityId);
        $townItem = Application_Model_city::load($townId);
        $prices = Application_Model_ExpressPrice::getPricesByCity($townId);
        foreach ($prices as $item){
            $item->SortKey = $item->Express->OrderBy;
        }
        
        $WayPrices = Application_Model_ExpressPrice::getPricesByCity($cId);
        
        foreach ($WayPrices as $WayItem){
            $WayItem->SortKey = $WayItem->Express->OrderBy;
        }
        
        $this->view->prices = Uuch_Util::quickSort($prices, 'SortKey');
        $this->view->WayPrices = $WayPrices;
        $this->view->cityAll = $cityItem;
        $this->view->townAll = $townItem;
        $this->view->isWay = $isWay;
        $this->view->city = $city;
        
        $this->disableLayout();
    }
    
    public function expresscultAction(){
        $weight = $this->getSafeParam('weight');
        $cityId = $this->getSafeParam('city');
        $city = Application_Model_city::load($cityId);
        $length = $this->getSafeParam('length');
        $width = $this->getSafeParam('width');
        $height = $this->getSafeParam('height');
        $volumeWeight = $weight;
        if($length && $width && $height)
        {
            $volumeWeight = ($length * $width * $height) / 5000.0;
            if($volumeWeight<$weight)
                $volumeWeight=$weight;
        }
        
        $this->view->length = $length;
        $this->view->width = $width;
        $this->view->height = $height;
        $this->view->weight =$weight;
        $this->view->volumeWeight = $volumeWeight;
        $this->view->city = $city;
        $this->view->prices = Application_Model_ExpressPrice::getPricesByCity($cityId);
        $this->disableLayout();
    }

    public function expressdetailAction(){
        $cityId = $this->getSafeParam('cityId');
        $this->view->city = Application_Model_city::load($cityId);
        $prices = Application_Model_ExpressPrice::getPricesByCity($cityId);
        foreach ($prices as $item){
            $item->SortKey = $item->Express->OrderBy;
        }
        $prices = Uuch_Util::quickSort($prices, 'firstPrice');
        $this->view->prices = $prices;
        $this->disableLayout();
    }

    public function shipfeeAction(){
        
        $this->appendScript('/js/jquery.min.js');
        
        $this->setTitle('国际运费估算 | 常用工具');
        $this->appendCss('/css/tool.css');
        $this->view->shipFeeConfig=Application_Model_shipFeeConfig::getbyType(2);
        
        $words = array();
        for($i=0;$i<26;$i++){
            $words []= chr(65+$i);
        }
        $this->view->words = $words;
    }
    
    
    public function getfeetypeAction(){
        $this->_helper->layout->disableLayout();
        $tid = $this->getRequest()->getParam('tid');
        $this->view->shipFeeConfig=Application_Model_shipFeeConfig::getbyType($tid);
        //$this->view->prices = Application_Model_Express::getPricesByExpress($tid);
        $type = Application_Model_shipType::load($tid);
        $this->view->type = $type;
    }

        //返回一个国家的所有运费
    public function getshipfeeAction(){
        $cid=$this->getRequest()->getParam('cid');

        //$this->view->fee = Application_Model_shipFeeConfig::getbyCityid($cid);
        
        $this->view->prices = Application_Model_Express::getPricesByCity($cid);
        
        $this->_helper->layout->disableLayout();
    }
    
    //根据重量和国家,返回估算后的结果
    public function getfeeAction(){
        $cid=$this->getRequest()->getParam('cid');
        $wed=  $this->getRequest()->getParam('weight');
        

        $this->view->prices = Application_Model_Express::getPricesByCity($cid);
        
        //$this->view->fee = Application_Model_shipFeeConfig::getbyCityid($cid);        
        $this->_helper->layout->disableLayout();
        
        $this->view->cid = $cid;
        $this->view->Weight = $wed;
    }
    
    public function cultfeeAction(){
        $cid=$this->getRequest()->getParam('cid');
        $wed=  $this->getRequest()->getParam('weight');
        $ids =  $this->getSafeParam('ids');
        
        $stores = Application_Model_StoreItem::getByids($ids);
        
        $this->view->prices = Application_Model_Express::getPricesByCity($cid);
        $this->_helper->layout->disableLayout();
        
                
        //$productCount = 0; 
        $weightCount = 0;
        //$timeOutCount = 0;
        
        $volumWeight = 0;

        foreach ($stores as $item) {
            if($item->WayId){
                $this->redirect('mystore', 'member');
                return;
            }
            
            $weightCount+=$item->weight; //计算总重量
            
            if($item->VolumeWeight){
                $volumWeight += $item->VolumeWeight;
            }  else {
                $volumWeight += $item->Weight;
            }
        }
        $packWeight = Uuch_Util::getPackage($weightCount);
        
        $this->view->weightCount = $weightCount; //总重量
        $this->view->packWeight = $packWeight; //包裹重量
        
        $this->view->volumeWeight = $volumWeight;
        
        $this->view->cid = $cid;
        $this->view->stores =$stores;
    }

    public function sizeAction(){
        //$this->_redirect('http://qq.ip138.com/converter8.htm');
        $this->appendCss('/css/tool.css');
        $this->setTitle('尺码换算');
    }
	
	public function sizenewAction(){
        //$this->_redirect('http://qq.ip138.com/converter8.htm');
        $this->appendCss('/css/tool.css');
        $this->setTitle('尺码换算');
		$this->_helper->layout()->setLayout('empty');
    }
    
    
    public function trackAction(){
        //$this->_redirect('http://www.ip138.com/ems/');
        $this->appendCss('/css/tool.css');
        $this->setTitle('物流跟踪查询');
    }
	
	
    public function tracknewAction(){
        //$this->_redirect('http://www.ip138.com/ems/');
        $this->appendCss('/css/tool.css');
        $this->setTitle('物流跟踪查询');
		$this->_helper->layout()->setLayout('empty');
    }
    
    public function rateAction(){
        //$this->_redirect('http://qq.ip138.com/hl.asp');
        $this->setTitle('汇率换算');
        $this->appendCss('/css/tool.css');
    }
	
	public function ratenewAction(){
        //$this->_redirect('http://qq.ip138.com/hl.asp');
        $this->setTitle('汇率换算');
        $this->appendCss('/css/tool.css');
		$this->_helper->layout()->setLayout('empty');
    }
    
    public function payAction(){
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/generationpay.css');
        
        $this->setTitle('跨国支付服务,华人国内支付好帮手');
        $this->redirect('payment');
    }
    
    public function payaskAction(){
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/generationpay.css');
        
        $this->setTitle('跨国支付服务,华人国内支付好帮手');
    }
    
    public function paycardAction(){
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/generationpay.css');
        
        $this->setTitle('跨国支付服务,华人国内支付好帮手');
    }
    
    public function paycardaskAction(){
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/generationpay.css');
        
        $this->setTitle('跨国支付服务,华人国内支付好帮手');
    }
    
    public function paymentAction(){
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/generationpay.css');
        
        $this->setTitle('跨国支付服务,华人国内支付好帮手');
    }
    
    public function payment2Action(){
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/generationpay.css');
        
        $this->setTitle('跨国支付服务,华人国内支付好帮手');
    }
    
    public function paymentaskAction(){
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/generationpay.css');
        
        $this->setTitle('跨国支付服务,华人国内支付好帮手');
    }
    
    
    public function linkAction(){
        $this->appendCss('/css/tool.css');
        $this->setTitle('友情链接');
        
    }
    
}